#include <cstdio>
#include <cstring>

struct tree_node {
    tree_node *left_child;
    tree_node *right_child;
    char data;
} binary_tree[50];

int assigned_num;

tree_node *creat_node() {
    binary_tree[assigned_num].left_child = binary_tree[assigned_num].right_child = nullptr;
    return &binary_tree[assigned_num++];
}

char pre_order_string[30];
char mid_order_string[30];

void post_order(tree_node *node) {
    if (node->left_child != nullptr)
        post_order(node->left_child);
    if (node->right_child != nullptr)
        post_order(node->right_child);
    printf("%c", node->data);
}

tree_node *build_tree(int start_1, int end_1, int start_2, int end_2) {
    tree_node *return_node = creat_node();
    return_node->data = pre_order_string[start_1];
    int root_index;
    for (int i = start_2; i <= end_2; ++i) {
        if (mid_order_string[i] == pre_order_string[start_1]) {
            root_index = i;
            break;
        }
    }
    if (root_index != start_2)
        return_node->left_child = build_tree(start_1 + 1, start_1 + (root_index - start_2), start_2, root_index - 1);
    if (root_index != end_2)
        return_node->right_child = build_tree(start_1 + (root_index - start_2) + 1, end_1, root_index + 1, end_2);
    return return_node;
}

int main(int argc, char const *argv[]) {
    while (scanf("%s", pre_order_string) != EOF) {
        scanf("%s", mid_order_string);
        assigned_num = 0;
        int length_1 = strlen(pre_order_string);
        int length_2 = strlen(mid_order_string);
        tree_node *tree = build_tree(0, length_1 - 1, 0, length_2 - 1);
        post_order(tree);
        printf("\n");
    }
    return 0;
}